package cn.org.zx.manage.user.blh;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.org.zx.common.commutils.StringUtils;
import cn.org.zx.common.dao.DBAccess;

public class UserBlh {
	//用户事务所查询--用户管理模块
	public Map<String, Object> getUserQueryList(Map<String, Object> mapData){		
		Map<String, Object> mapReturn = new HashMap<String, Object>();
		String strPerPage = StringUtils.toString(mapData.get("numPerPage"));
		String currentPage = StringUtils.toString(mapData.get("pageNum"));
		
		String struname = StringUtils.toString(mapData.get("unameq"));			//姓名
		String strphoneq = StringUtils.toString(mapData.get("uphoneq"));		//手机号
		String strgeneralq = StringUtils.toString(mapData.get("ugeneralq"));	//全科合格证号
		String strcardidq = StringUtils.toString(mapData.get("ucardidq"));		//身份证号
		String strappdatebegq = StringUtils.toString(mapData.get("uappdatebegq"));	//申请日期
		String strappdateendq = StringUtils.toString(mapData.get("uappdateendq"));	//申请日期
		String strSql = "";

		int iPageNum = 20;
		int iCurrentPage = 1;
		int iTotalCount=0;
						
		if(!currentPage.equals("")) iCurrentPage = Integer.parseInt(currentPage);
		if(!strPerPage.equals("")) iPageNum = Integer.parseInt(strPerPage);
		
		strSql="select * from tb_demo where 1=1";
		if(!struname.equals("")){
			strSql+=" and self_name like '%"+struname+"%'";
		}
		if(!strphoneq.equals("")){
			strSql+=" and self_phone like '%"+strphoneq+"%'";
		}
		if(!strgeneralq.equals("")){
			strSql+=" and self_general like '%"+strgeneralq+"%'";
		}
		if(!strcardidq.equals("")){
			strSql+=" and self_id_card like '%"+strcardidq+"%'";
		}
		if(!strappdatebegq.equals("")){
			strSql+=" and to_char(create_time,'yyyy-mm-dd')>='"+strappdatebegq+"'";
		}
		if(!strappdateendq.equals("")){
			strSql+=" and to_char(create_time,'yyyy-mm-dd')<='"+strappdateendq+"'";
		}
		
		List<?> datalist = DBAccess.queryOnePage(strSql, "d_id desc", iPageNum,iCurrentPage);	
		iTotalCount=DBAccess.getResultCount(strSql);				
		mapReturn.put("totalCount", iTotalCount);		
		mapReturn.put("pageNum", iCurrentPage);
		mapReturn.put("numPerPage", iPageNum);		
		mapReturn.put("datalist", datalist);
		
		return mapReturn;
	}
	
	//
	public Map<String, Object> getUserCreateSave(Map<String, Object> mapData,String strIP){
		Map<String, Object> mapReturn = new HashMap<String, Object>();
		String strSql = "";		
				
		String strselfname = StringUtils.toString(mapData.get("selfName"));						//姓名
		String strselfphone = StringUtils.toString(mapData.get("selfPhone"));					//手机号	
		String strselfidcard = StringUtils.toString(mapData.get("selfIdCard"));					//身份证号码后六位	
		String strselfgeneral = StringUtils.toString(mapData.get("selfGeneral"));				//全科合格证号
		
		String strselfunit = StringUtils.toString(mapData.get("selfUnit"));						//目前所在单位
		String strapply = StringUtils.toString(mapData.get("apply"));							//是否拟申请加入上海注册会计师协会		
		String strcre = StringUtils.toString(mapData.get("crew"));								//是否属于军队人员
		
		String strimg1 = StringUtils.toString(mapData.get("img1"));								//图片路径
		
		String strconsigneename = StringUtils.toString(mapData.get("consigneeName"));			//收件人姓名		
		String strconsigneephone = StringUtils.toString(mapData.get("consigneePhone"));			//收件人手机号码
		String strconsigneeaddress = StringUtils.toString(mapData.get("consigneeAddress"));		//收件人详细地址
						
		if(!strIP.equals("") && !strselfgeneral.equals("")){
			strSql="select * from tb_demo where self_general='"+strselfgeneral.toUpperCase()+"'";
			Map map = DBAccess.queryOneRow(strSql);
			if(map==null){			
				strSql="insert into tb_demo(d_id,self_name,self_phone,self_id_card,self_general,";
				strSql+="self_unit,apply,crew,img1,";			
				strSql+="consignee_name,consignee_phone,consignee_address,create_time,d_ipadress)values(";
				strSql+="ssdemoid.nextval,'"+strselfname+"','"+strselfphone+"','"+strselfidcard+"','"+strselfgeneral.toUpperCase()+"',";
				strSql+="'"+strselfunit+"','"+strapply+"','"+strcre+"','"+strimg1+"',";
				strSql+="'"+strconsigneename+"','"+strconsigneephone+"','"+strconsigneeaddress+"',sysdate,'"+strIP+"')";
				System.out.println("strSql="+strSql);						
				mapReturn.put("code", DBAccess.update(strSql)==true?"0":"500");
			}
			else{
				mapReturn.put("code","100");
				mapReturn.put("msg","全科合格证号已有！");
			}
		}
		
		return mapReturn;
	}
	
	//导出
	public Map<String, Object> getUserExport(Map<String, Object> mapData){		
		Map<String, Object> mapReturn = new HashMap<String, Object>();
		
		String struname = StringUtils.toString(mapData.get("unameq"));			//姓名
		String strphoneq = StringUtils.toString(mapData.get("uphoneq"));		//手机号
		String strgeneralq = StringUtils.toString(mapData.get("ugeneralq"));	//全科合格证号
		String strcardidq = StringUtils.toString(mapData.get("ucardidq"));		//身份证号
		String strappdatebegq = StringUtils.toString(mapData.get("uappdatebegq"));	//申请日期
		String strappdateendq = StringUtils.toString(mapData.get("uappdateendq"));	//申请日期
		String strSql = "";

		strSql="select * from tb_demo where 1=1";
		if(!struname.equals("")){
			strSql+=" and self_name like '%"+struname+"%'";
		}
		if(!strphoneq.equals("")){
			strSql+=" and self_phone like '%"+strphoneq+"%'";
		}
		if(!strgeneralq.equals("")){
			strSql+=" and self_general like '%"+strgeneralq+"%'";
		}
		if(!strcardidq.equals("")){
			strSql+=" and self_id_card like '%"+strcardidq+"%'";
		}
		if(!strappdatebegq.equals("")){
			strSql+=" and to_char(create_time,'yyyy-mm-dd')>='"+strappdatebegq+"'";
		}
		if(!strappdateendq.equals("")){
			strSql+=" and to_char(create_time,'yyyy-mm-dd')<='"+strappdateendq+"'";
		}
				
		mapReturn.put("datalist", DBAccess.query(strSql));
		
		return mapReturn;
	}
	
}
